import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MathExercisesGrader {
    private static final String INPUT_FILE = "SelectedExercises.csv";
    private static final String GRADED_FILE = "GradedExercises.csv";

    public static void main(String[] args) {
        try (BufferedReader reader = new BufferedReader(new FileReader(INPUT_FILE));
             BufferedWriter writer = new BufferedWriter(new FileWriter(GRADED_FILE))) {

            writer.write("Expression,Submitted Answer,Is Correct\n");

            String line;
            Pattern pattern = Pattern.compile("^(\\d+) (\\+|-) (\\d+),(\\d+)$");
            while ((line = reader.readLine()) != null) {
                Matcher matcher = pattern.matcher(line);
                if (matcher.find()) {
                    int num1 = Integer.parseInt(matcher.group(1));
                    String operation = matcher.group(2);
                    int num2 = Integer.parseInt(matcher.group(3));
                    int submittedAnswer = Integer.parseInt(matcher.group(4));

                    int correctAnswer = operation.equals("+") ? num1 + num2 : num1 - num2;
                    boolean isCorrect = submittedAnswer == correctAnswer;

                    writer.write(matcher.group(0) + "," + isCorrect + "\n");
                }
            }

            System.out.println("Grading results have been written to " + GRADED_FILE);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}